package br.com.robot;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import br.com.robot.implement.AbstractRobot;
import br.com.robot.implement.nuuvem.Nuuvem;
import br.com.robot.implement.nuuvem.Nuuvem_Games;
import br.com.robot.implement.steam.Steam;
import br.com.robot.implement.steam.Steam_Games;


public class RobotList 
{
	public static final int ID_STEAM_ROBOT        = 1,
							ID_NUUVEM_ROBOT       = 2,
	                        ID_NUUVEM_GAMES_ROBOT = 3,
	                        ID_STEAM_GAMES_ROBOT  = 4;
	
	private static List<RobotBean<? extends AbstractRobot>> container;
	
	private static void ajustaContainer( )
	{
		if( container == null )
		{
			RobotBean<?>[] array = 
			{
				new RobotBean<Steam>       ( ID_STEAM_ROBOT,        "STEAM_ROBOT",        Steam.class        ),
				new RobotBean<Nuuvem>      ( ID_NUUVEM_ROBOT,       "NUUVEM_ROBOT",       Nuuvem.class       ),
				new RobotBean<Nuuvem_Games>( ID_NUUVEM_GAMES_ROBOT, "NUUVEM_GAMES_ROBOT", Nuuvem_Games.class ),
				new RobotBean<Steam_Games> ( ID_STEAM_GAMES_ROBOT,  "STEAM_GAMES_ROBOT",  Steam_Games.class  ),
			};
			
			container =	Arrays.asList( array );
		}
	}
	
	public static List<RobotBean<? extends AbstractRobot>> getContainer( )
	{
		ajustaContainer( );
		
		return container;
	}
	
	public static RobotBean<? extends AbstractRobot> getBean( int id )
	{
		ajustaContainer( );

		for( RobotBean<? extends AbstractRobot> bean : container )
		{
			if( bean.getId( ) == id )
			{
				return bean;
			}
		}
		
		return null;
	}
	
	public static List<RobotBean<? extends AbstractRobot>> getBeans( int... ids )
	{
		ajustaContainer( );

		List<RobotBean<? extends AbstractRobot>> lst = new ArrayList<RobotBean<? extends AbstractRobot>>( );
		
		for( RobotBean<? extends AbstractRobot> bean : container )
		{
			for( int id : ids )
			{
				if( bean.getId( ) == id )
				{
					lst.add( bean );
				}
			}
		}
		
		return lst;
	}
}